/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the header for the DetailTab
 * QT class which is an abstraction to factor out some
 * common functionality from the tab widgets which
 * facilitate the entering of information */

#ifndef DETAILTAB_H
#define DETAILTAB_H

#include <QWidget>
#include <QTcpSocket>
#include <QTabWidget>
#include "../lib/user.h"

class DetailTab : public QWidget
{
    Q_OBJECT
    public:
        explicit DetailTab(User* user, QWidget *parent = 0);

    protected:
        QTabWidget* myTabWidget;        /* Parent class */
        QTcpSocket* mySock;             /* A pointer to the socket that will be created here */
        User* myUser;                   /* User Pointer for key exchange */

        /* This function validates the inputed details
         * it is implemented in the subclasses because it
         * is specific to direct and server connections */
        virtual QString checkInput() = 0;

        /* This function initiates a connection over the socket
         * it is implemented in the subclasses because it
         * is specific to direct and server connections */
        virtual void connectSocket( QTcpSocket* sock ) = 0;

        /* This function starts a new chat. It is implemented
         * in the specific subclasses because it is different
         * in direct and server connections */
        virtual void beginChat() = 0;

        /* This function is a pure virtual to allow the
         * subclasses to provide access to the hostname/IP
         * that the user has entered */
        virtual QString getAddress() = 0;

        /* An event filter to grab enter key presses and
         * use them to press the OK button */
        bool eventFilter( QObject* obj, QEvent* event );

    private slots:
        /* This slot is connected to the socket's connected() signal
         * which is triggered when the socket has become connected */
        void connectionEstablished();

        /* This slot is connected to the lookup dialog and is triggered
         * when the user cancels the connecting process */
        void connectionCancelled();

        /* This slot is connected to the socket's error() signal
         * and it displays the error message() */
        void socketError( QAbstractSocket::SocketError e );

        void buttonOk_clicked();        /* Activated on a click of the OK button */
        void buttonBack_clicked();      /* Activated on a click of the BACK button */
};

#endif // DETAILTAB_H
